TOOL.Category			= "Mineral Mining";
TOOL.Name				= "Mining Storage";

TOOL.DeviceName			= "Mining Storage Device"
TOOL.DeviceNamePlural	= "Mining Storage Devices"
TOOL.ClassName			= "mining_storage_tool"

TOOL.DevSelect			= true
TOOL.CCVar_type			= "storage_ore"
TOOL.CCVar_sub_type		= "ore_storage"
TOOL.CCVar_model		= "models/mandrac/ore_container/ore_large.mdl"

TOOL.Limited			= true
TOOL.LimitName			= "mining_storage_limit"
TOOL.Limit				= 30

CAFToolSetup.SetLang("Mining Storage Devices","Create Mining Storage Devices attached to any surface.","Left-Click: Spawn a Mining Storage Device.")

if (CLIENT and GetConVarNumber("CAF_UseTab") == 1) then TOOL.Tab = "Custom Addon Framework" end

function TOOL.EnableFunc()
	if not CAF then
		return false;
	end
	if not CAF.GetAddon("Resource Distribution") or not CAF.GetAddon("Resource Distribution").GetStatus() then
		return false;
	end
	return true;
end

TOOL.ExtraCCVars = {
}

function TOOL.ExtraCCVarsCP( tool, panel )
end

function TOOL:GetExtraCCVars()
	local Extra_Data = {}
	return Extra_Data
end

local function ore_func(ent,type,sub_type,devinfo,Extra_Data,ent_extras) 
	local volume_mul = 1
	local base_volume = 600
	local base_mass = 5
	local base_health = 200
	local phys = ent:GetPhysicsObject()
	if phys:IsValid() and phys.GetVolume then
		local vol = phys:GetVolume()
		vol = math.Round(vol)
		volume_mul = vol/base_volume
	end
	CAF.GetAddon("Resource Distribution").AddResource(ent, "Ore", math.Round(3600 * volume_mul))
	ent.MAXRESOURCE = math.Round(3600 * volume_mul)
	local mass = math.Round(base_mass * volume_mul)
	ent.mass = mass
	local maxhealth = math.Round(base_health * volume_mul)
	return mass, maxhealth 
end

local function crystal_func(ent,type,sub_type,devinfo,Extra_Data,ent_extras) 
	local volume_mul = 1
	local base_volume = 600
	local base_mass = 5
	local base_health = 200
	local phys = ent:GetPhysicsObject()
	if phys:IsValid() and phys.GetVolume then
		local vol = phys:GetVolume()
		vol = math.Round(vol)
		volume_mul = vol/base_volume
	end
	CAF.GetAddon("Resource Distribution").AddResource(ent, "Crystals", math.Round(3600 * volume_mul))
	ent.MAXRESOURCE = math.Round(3600 * volume_mul)
	local mass = math.Round(base_mass * volume_mul)
	ent.mass = mass
	local maxhealth = math.Round(base_health * volume_mul)
	return mass, maxhealth 
end

local function polonium_func(ent,type,sub_type,devinfo,Extra_Data,ent_extras)
	local volume_mul = 1
	local base_volume = 600
	local base_mass = 5
	local base_health = 200
	local phys = ent:GetPhysicsObject()
	if phys:IsValid() and phys.GetVolume then
		local vol = phys:GetVolume()
		vol = math.Round(vol)
		volume_mul = vol/base_volume
	end
	CAF.GetAddon("Resource Distribution").AddResource(ent, "Polonium Nitrate", math.Round(3600 * volume_mul))
	ent.MAXRESOURCE = math.Round(3600 * volume_mul)
	local mass = math.Round(base_mass * volume_mul)
	ent.mass = mass
	local maxhealth = math.Round(base_health * volume_mul)
	return mass, maxhealth 
end

local function pnfuel_func(ent,type,sub_type,devinfo,Extra_Data,ent_extras) 
	local volume_mul = 1
	local base_volume =  8671.24
	local base_mass = 5
	local base_health = 200
	local phys = ent:GetPhysicsObject()
	
	if phys:IsValid() and phys.GetVolume then
		local vol = phys:GetVolume()
		vol = math.Round(vol)
		volume_mul = math.Clamp(vol,0,867124)/base_volume
	end
	
	local PAmount = 0
	
	if ent:GetModel() == "models/ce_ls3additional/resource_tanks/resource_tank_tiny.mdl" then
		PAmount = 10000
	elseif ent:GetModel() == "models/ce_ls3additional/resource_tanks/resource_tank_small.mdl" then
		PAmount = 30000
	elseif ent:GetModel() == "models/ce_ls3additional/resource_tanks/resource_tank_medium.mdl" then
		PAmount = 100000
	elseif ent:GetModel() == "models/ce_ls3additional/resource_tanks/resource_tank_large.mdl" then
		PAmount = 500000
	end
	
	CAF.GetAddon("Resource Distribution").AddResource(ent, "PN-Fuel", PAmount)
	
	local mass = math.Round(base_mass * volume_mul)
	ent.mass = mass
	local maxhealth = math.Round(base_health * volume_mul)
	return mass, maxhealth 
end

TOOL.Devices = {
	
	storage_ore = {
		Name	= "Ore Container",
		type	= "storage_ore",
		class	= "storage_ore",
		func	= ore_func,
		devices = {
			ore_storage_large = {
				Name	= "Small Ore Container ",
				model	= "models/mandrac/ore_container/ore_small.mdl",
				skin	= 0,
				res		= { Ore = 500000},
				mass	= 1000,
				ent_extras = { TankPoints = 1 },
				legacy	= false,
			},
			ore_storage_medium = {
				Name	= "Medium Ore Container ",
				model	= "models/mandrac/ore_container/ore_medium.mdl",
				skin	= 0,
				res		= { Ore = 1000000},
				mass	= 1500,
				ent_extras = { TankPoints = 3 },
				legacy	= false,
			},
			ore_storage_large = {
				Name	= "Large Ore Container ",
				model	= "models/mandrac/ore_container/ore_large.mdl",
				skin	= 0,
				res		= { Ore = 1500000 },
				mass	= 2500,
				ent_extras = { TankPoints = 6 },
				legacy	= false, --these two vars must be defined per ent as the old tanks (defined in external file) require different values
			},
		},
	},
	
	storage_crystal = {
		Name	= "Crystal Container",
		type	= "storage_crystal",
		class	= "storage_crystal",
		func	= crystal_func,
		devices = {
			crystal_storage = {
				Name	= "Crystal Container ",
				model	= "models/mandrac/ore_container/ore_medium.mdl",
				skin	= 0,
				res		= { Crystals = 100000 },
				mass	= 200,
				legacy	= false,
			},
		},
	},
	
	storage_polonium = {
		Name	= "Polonium Container",
		type	= "storage_polonium",
		class	= "storage_polonium",
		func	= polonium_func,
		devices = {
			storage_polonium = {
				Name	= "Polonium Container ",
				model	= "models/mandrac/ore_container/ore_medium.mdl",
				skin	= 0,
				res		= { Polonium Nitrate = 100000 },
				mass	= 200,
				legacy	= false,
			},
		},
	},
	
	storage_pnfuel = {
		Name	= "PN-Fuel Tanks",
		type	= "storage_pnfuel",
		class	= "storage_pnfuel",
		func	= pnfuel_func,
		devices = {
			pnfuel_storage_small = {
				Name	= "Small PN-Fuel Tank ",
				model	= "models/ce_ls3additional/resource_tanks/resource_tank_tiny.mdl",
				skin	= 0,
				res		= {},
				mass	= 200,
				ent_extras = { TankPoints = 1 },
				legacy	= false,
			},
			pnfuel_storage_medium = {
				Name	= "Medium PN-Fuel Tank ",
				model	= "models/ce_ls3additional/resource_tanks/resource_tank_small.mdl",
				skin	= 0,
				res		= {},
				mass	= 600,
				ent_extras = { TankPoints = 3 },
				legacy	= false,
			},
			pnfuel_storage_large = {
				Name	= "Large PN-Fuel Tank ",
				model	= "models/ce_ls3additional/resource_tanks/resource_tank_medium.mdl",
				skin	= 0,
				res		= {},
				mass	= 1500,
				ent_extras = { TankPoints = 6 },
				legacy	= false,
			},
			pnfuel_storage_station = {
				Name	= "Station PN-Fuel Tank ",
				model	= "models/ce_ls3additional/resource_tanks/resource_tank_large.mdl",
				skin	= 0,
				res		= {},
				mass	= 5000,
				ent_extras = { TankPoints = 20 },
				legacy	= false,
			}
		}
	}
}